<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.">
    <title>案例</title>
</head>

<body>
    用户名:<input type="text" id="username">
    <p></p>
    <script>
        const input = document.querySelector("input");
        const p = document.querySelector("p");
        const BASE_URL = "http://localhost:8000"
        input.addEventListener("blur", () => {
            let username = this.value;
            // 1.
            const script = document.createElement("script");
            // 2.
            script.src = BASE_URL+"/jsonp-check-username";
            // 3.
            document.body.appendChild(script);
        });

        handle = function (data) {
            input.style.border = "solid 1px #f00";
            p.innerHTML = data.msg;
        }
    </script>
</body>

</html>